﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Cashier
{
    class customer_form_offline : customer_form
    {
        public customer_form_offline() : base()
        {
            groupBox4.Location = new Point(groupBox3.Location.X, groupBox3.Location.Y);
            groupBox5.Location = new Point(groupBox3.Location.X, groupBox4.Height + 10);
            groupBox5.Height = this.Height - groupBox5.Location.Y - 50;
            groupBox3.Dispose();
            
        }

        protected override void txt_condition_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                List<Customer> listcustomer = new List<Customer>();
                int x = cb_searchby.SelectedIndex;
                using (DatabaseServices DBServices = new DatabaseServices())
                {
                    if (cb_searchby.SelectedIndex == 0)
                    {
                        listcustomer = DBServices.GetCustomerListByConditionLocal("card_id LIKE '" + txt_condition.Text + "%'");
                    }
                    else if (cb_searchby.SelectedIndex == 1)
                    {
                        listcustomer = DBServices.GetCustomerListByConditionLocal("full_name LIKE '%" + txt_condition.Text + "%'");
                    }
                    if (listcustomer.Count > 0)
                    {
                        DGV_customer.Rows.Clear();
                        DGV_customer.Rows.Add(listcustomer.Count);
                        DGV_customer.Refresh();
                        int i = 0;
                        foreach (Customer customer in listcustomer)
                        {
                            DGV_customer[0, i].Value = customer.card_id;
                            DGV_customer[1, i].Value = customer.full_name;
                            DGV_customer[2, i].Value = customer.phone;
                            DGV_customer[3, i].Value = customer.address;
                            DGV_customer[4, i].Value = customer.join_date.Date.ToString();
                            DGV_customer[5, i].Value = customer.point;
                            DGV_customer[6, i].Value = customer.birthday.Date.ToString();
                            DGV_customer[7, i].Value = customer.gender;
                            DGV_customer[8, i].Value = customer.vip;
                            i++;
                        }
                    }
                }
            }
            
        }
    }
}
